package cn.szzsi.service;

import cn.szzsi.common.model.OrderLog;
import cn.szzsi.common.model.Orders;
import cn.szzsi.common.model.Payment;
import cn.szzsi.common.model.PaymentConfig;

import java.math.BigDecimal;

/**
 *  支付业务类
 * Created by zhengy on 2017/3/10.
 */
public class PaymentService {
    public static final PaymentService service=new PaymentService();
    /**
     *  订单支付信息
     * @param paymentType
     * @param paymentConfigName
     * @param totalAmount
     * @param paymentFee
     * @param payer
     * @param paymentStatus
     * @param paymentConfigId
     * @param orderId
     * @param paymentSn
     * @param shopId
     */
    public void savePayment(Integer paymentType,String paymentConfigName,BigDecimal totalAmount, BigDecimal paymentFee,String payer,Integer paymentStatus,String paymentConfigId,String orderId,String paymentSn,String shopId){
        Payment payment = new Payment();
        payment.set("paymentType",paymentType);
        payment.set("paymentConfigName",paymentConfigName);
        payment.set("bankName",null);
        payment.set("bankAccount",null);
        payment.set("totalAmount",totalAmount);
        payment.set("paymentFee",paymentFee);
        payment.set("payer",payer);
        payment.set("operator",null);
        payment.set("memo",null);
        payment.set("paymentStatus",paymentStatus);
        payment.set("paymentConfig_id",paymentConfigId);
        //payment.set("deposit_id",deposit.getStr("id"));
        payment.set("order_id",orderId);
        payment.set("paymentSn", paymentSn);
        payment.set("uid",shopId);
        payment.save(payment);
    }

    /**
     * 订单日志
     * @param order
     * @param paymentConfig
     * @param totalAmount
     */
    public void saveOrderLog(Integer OrderLogType,Orders order, PaymentConfig paymentConfig,BigDecimal totalAmount){
        OrderLog orderLog = new OrderLog();
        orderLog.set("orderLogType", OrderLogType);
        orderLog.set("orderSn",order.getStr("orderSn"));
        if(paymentConfig!=null){
            if(paymentConfig.getPaymentConfigTypeValue() == PaymentConfig.PaymentConfigType.point) {
                orderLog.set("info", "支付总积分：" + totalAmount);
            }else{
                orderLog.set("info", "支付总金额：" + totalAmount);
            }
        }
        orderLog.set("operator",null);
        orderLog.set("order_id",order.getStr("id"));
        orderLog.save(orderLog);
    }
}
